From 16324b1affd81722aa3317eec67804329f943a2d Mon Sep 17 00:00:00 2001 From: Alastair Tse Date: Wed, 24 Jan 2007 15:59:09 +0000 Subject: [PATCH] [XEND] Add debug class to Xen API plus non-standard debug.wait(). debug.wait(seconds) will just do a time.sleep() so the task progress support can be tested. Signed-off-by: Alastair Tse --- tools/python/scripts/xapi.py | 2 +- tools/python/xen/xend/XendAPI.py | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/python/scripts/xapi.py b/tools/python/scripts/xapi.py index 8e17354597..930395b6a8 100644 --- a/tools/python/scripts/xapi.py +++ b/tools/python/scripts/xapi.py @@ -662,7 +662,7 @@ def xapi_debug_wait(args, async = False): if len(args) > 0: secs = int(args[0]) server, session = connect() - task_uuid = execute(server, 'Debug.wait', (session, secs), async=async) + task_uuid = execute(server, 'debug.wait', (session, secs), async=async) print 'Task UUID: %s' % task_uuid # diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 0c7355a662..309bd20bbd 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -260,6 +260,17 @@ def valid_task(func): _check_ref(XendTaskManager.get_task, 'TASK_HANDLE_INVALID', func, *args, **kwargs) +def valid_debug(func): + """Decorator to verify if task_ref is valid before calling + method. + + @param func: function with params: (self, session, task_ref) + @rtype: callable object + """ + return lambda *args, **kwargs: \ + _check_ref(lambda r: r in XendAPI._debug, + 'TASK_HANDLE_INVALID', func, *args, **kwargs) + # ----------------------------- # Bridge to Legacy XM API calls # ----------------------------- @@ -300,6 +311,7 @@ class XendAPI(object): __decorated__ = False __init_lock__ = threading.Lock() + _debug = {} def __new__(cls, *args, **kwds): """ Override __new__ to decorate the class only once. @@ -337,6 +349,7 @@ class XendAPI(object): 'SR' : valid_sr, 'PIF' : valid_pif, 'task' : valid_task, + 'debug' : valid_debug, } # Cheat methods @@ -1866,6 +1879,40 @@ class XendAPI(object): return xen_api_success_void() + # Xen API: Class debug + # ---------------------------------------------------------------- + + debug_methods = [('destroy', None), + ('get_record', 'debug')] + debug_funcs = [('wait', None), + ('return_failure', None)] + + def debug_wait(self, session, wait_secs): + import time + prog_units = 100/float(wait_secs) + for i in range(int(wait_secs)): + XendTask.log_progress(prog_units * i, prog_units * (i + 1), + time.sleep, 1) + return xen_api_success_void() + + + def debug_return_failure(self, session): + return xen_api_error(['DEBUG_FAIL', session]) + + def debug_create(self, session): + debug_uuid = uuid.createString() + self._debug[debug_uuid] = None + return xen_api_success(debug_uuid) + + def debug_destroy(self, session, debug_ref): + del self._debug[debug_ref] + return xen_api_success_void() + + def debug_get_record(self, session, debug_ref): + return xen_api_success({'uuid': debug_ref}) + + + class XendAPIAsyncProxy: """ A redirector for Async.Class.function calls to XendAPI but wraps the call for use with the XendTaskManager. -- 2.30.2